var main = {};
var myScroll;
var canLoad=true;
(function($){
    main.init = function () {
        document.addEventListener('touchmove', function (e) {
            e.preventDefault();
        }, false);

    };

    /**
     * @func move()
     * @desc 监听滚动条的位置，异步加载列表
     */
    var pageNumber= 1;
    function move() {
    	if(!canLoad){
    		return;
    	}
        if (myScroll.y < main.max - 80) {
        	canLoad=false;
        	pageNumber++;
        	var path = $("#path").val();
        	var resources = $("#resources").val();
            $("#tip").hide();
            $.ajax({
                type: "GET",
                url: path+"/manage/vote/empRankingMore",
                data:{
                	pageNumber:pageNumber,
                	pageSize:10
                },
                dataType: "json",
                success: function(data){
                	var html = "";
                	if(data.code==000){
                		for (var i=0;i<data.result.length;i++){
                			var emp = data.result[i];
                	      html += '<li>'+
                          '<a href="#">'+
                          '<div class="conLeft">'+
                          '<span><img src="'+emp.headimg+'">'+
                          '<img src="'+resources+'/vote/4_29_09.png">'+
                          '</span>'+
                          '</div>'+
                          '<div class="intro">'+
                          '<span>姓名:'+ emp.name+'</span>'+
                          '<span>票数:'+emp.votes+'</span>'+
                         '<span>部门:'+ emp.cooprt.name+'</span>'+
                         '</div>'+
                         '</a>'+
                         '<span class="sort">TOP'+((pageNumber-1)*10+i+1)+'</span>'+
                         '</li>'
                		}  
                	}
                	$("#list").append(html);
                	if(data.result.length<10){
                		canLoad=false;
                	}else{
                		canLoad=true;
                		$("#tip").show();
                	}
                	myScroll.refresh();
                	main.max = myScroll.maxScrollY;
                }
               });
            var html = "";
        }
    }

    /**
     * @func main.scroll()
     * @desc 配置iscroll插件
     */
    main.scroll = function () {
        myScroll = new IScroll(".mainbody", {probeType: 3, mouseWheel: true, click: true, preventDefault: false});
        main.max = myScroll.maxScrollY;
        myScroll.on("scroll", move);
    }
})(jQuery)

